<template>
  <div>
    <div class="charges_top">
      <div>
        <p>{{sort}}</p>
        <p class="txt">您上{{sortType()}}排名</p>
      </div>
    </div>
    <div class="list">
      <div class="list-item list-title">
        <span>排名</span>
        <span>{{ftitle_agents}}</span>
        <span>收入{{commission_name}}</span>
      </div>
      <van-list
        v-show="list.length"
        v-model="loading"
        :error.sync="error"
        error-text="请求失败，点击重新加载"
        :finished="finished"
        @load="onLoad"
      >
        <div class="list-item" v-for="(item, index) in list" :key="index">
          <span>
            <i :class="getCls(item.sort)">{{getText(item.sort)}}</i>
          </span>
          <span>{{item.user_name || '--'}}</span>
          <span>{{mSymbol.name}}{{item.commission}}</span>
        </div>
      </van-list>
      <no-data v-show="!list.length && finished" :noData="noData"></no-data>
    </div>
  </div>
</template>

<script>
import noData from '@/components/noData/index'
import Vue from 'vue'
import { List } from 'vant'
import { getCommissionSort } from '@/api/user/fxs/fxsApi'
import { mapGetters } from 'vuex'

Vue.use(List)
export default Vue.extend({
  data() {
    return {
      noData: {
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no-order-rank.png',
        text: '暂无排名',
        width: '214px',
        txtMarginTop: '-46px'
      },
      display_sort_type: '',
      sort: null,
      ftitle_agents: '',
      commission_name: '',
      p: 2,
      list: [],
      error: false,
      loading: false,
      finished: false
    }
  },
  created() {
    this.init()
    // 小程序触底加载更多
    window.addEventListener('reachbottom', () => {
      this.onLoad()
    })
  },
  methods: {
    init() {
      // console.log('commission_name')
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)
      this.onLoad()
    },
    sortType() {
      return this.display_sort_type == 1 ? '月' : '周'
    },
    onLoad() {
      getCommissionSort().then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
            wx.setNavigationBarTitle({
              title: res.data.ftitle_ranking
            })
          this.display_sort_type = res.data.display_sort_type
          this.sort = res.data.sort
          this.ftitle_agents = res.data.ftitle_agents
          this.commission_name = res.data.commission_name
          this.list = Object.values(res.data.lists)
          // if (!this.list.length) {
          this.finished = true
          // }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    getCls(sort) {
      if (sort <= 3) {
        return `icon icon${sort}`
      } else {
        return 'text'
      }
    },
    getText(sort) {
      if (sort > 3) {
        return sort
      }
    }
  },
  components: {
    noData
  },
  computed: {
    // 获取自定义符号
    ...mapGetters(['mSymbol'])
  },
})
</script>

<style lang="scss">
@import 'src/styles/variables';
@import 'src/styles/mixin';

.charges_top {
  height: 340px;
  // line-height: 80px;
  text-align: center;
  background-color: #f0f0f0;
  background: url('https://img.wifenxiao.com/h5-wfx/images/user/point_bg_rank.png') no-repeat;
  background-size: 100% 100%;
  padding: 60px 0 0;
  color: #fff;
  p:first-child {
    font-size: 50px;
    font-weight:bold;
  }
  .txt {
    font-size: 26px;
    margin-top: 20px;
    color:#FFD9DD;
  }
}
.list {
  margin: -100px 20px 0;
  background-color: $default;
  border-radius: 20px;
  overflow: hidden;
  &-title {
    &.list-item{
      display: flex;
      align-items: center;
      height: 100px;
      span{
        font-size: 26px;
        &:nth-child(3) {
          font-size: 26px;
          color:#333;
        }
      }
    }
  }
  &-item {
    height: 96px;
    display: flex;
    align-items: center;
    margin: 0 24px;
    border-bottom: 2px solid #EDEDED;
    &.list-title{
      span{
        &:nth-child(3) {
          padding-right: 60px;
          font-weight:normal;
        }
      }
    }
    span {
      font-size: 28px;
      text-align:center;
      color: #333;
      &:nth-child(1) {
        // margin-left: 75px;
        width: 19%;
      }
      &:nth-child(2) {
        width: 46%;
        text-align: left;
        padding-left: 11%;
      }
      &:nth-child(3) {
        width: 35%;
        font-size:30px;
        font-weight:bold;
        color:#FD2049;
        text-align: right;
        padding-right: 30px;
      }
      .icon,
      .text {
        display:block;
        width: 80px;
        height: 50px;
        margin:0 auto;
        line-height: 50px;
        font-weight: bold;
        text-align: center;
        background-size: auto 100%;
        background-position: center;
        background-repeat: no-repeat;
        &.icon1 {
          background-image: url('https://img.wifenxiao.com/h5-wfx/images/user/No1.png');
        }
        &.icon2 {
          background-image: url('https://img.wifenxiao.com/h5-wfx/images/user/No2.png');
        }
        &.icon3 {
          background-image: url('https://img.wifenxiao.com/h5-wfx/images/user/No3.png');
        }
      }
    }
    &:last-child {
      border-bottom: none;
    }
  }
}
</style>
